grammar NewsRequestAST;

options {
output=AST;
language=Java;
}

@header {
package com.dynamicalsoftware.news.parser;
}
@lexer::header {
package com.dynamicalsoftware.news.parser;
}

ask	:
	(
	repository
	|
	topic
	|
	interests
	|
	format
	|
	count
	)+
	;
repository	:
	'repository:' STRING -> ^(  'repository:' STRING )
	;
topic	:
	'topic:' STRING -> ^( 'topic:' STRING )
	;
interests	:
	'interest:' STRING ( ',' STRING )* -> ^( 'interest:' STRING+ )
	;
format	:
	'format:' STRING -> ^( 'format:' STRING )
	;
count	:
	'count:' INT -> ^( 'count:' INT )
	;
INT :	'0'..'9'+
    ;

WS  :   ( ' '
        | '\t'
        | '\r'
        | '\n'
        )+ {$channel=HIDDEN;}
    ;

STRING
    :  '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
    ;

fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UNICODE_ESC
    |   OCTAL_ESC
    ;

fragment
OCTAL_ESC
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UNICODE_ESC
    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
    ;
